package com.dc;

import com.dc.netty.TcpServer;
import io.netty.channel.ChannelFuture;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

import javax.annotation.Resource;

@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
@EnableDiscoveryClient
@EnableFeignClients
public class DcFireDeviceApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(DcFireDeviceApplication.class, args);
    }

    @Resource
    TcpServer tcpServer;

    @Override
    public void run(String... args) {
        //启动服务端
        ChannelFuture channelFuture = tcpServer.start();
        //服务端管道关闭的监听器并同步阻塞,直到channel关闭,线程才会往下执行,结束进程
        channelFuture.channel().closeFuture().syncUninterruptibly();
    }
}
